package com.way.cloud.controller;

import com.way.cloud.domain.Customer;
import com.way.cloud.service.CustomerService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RequestMapping("/customer")
@RestController
public class CustomerController {

    @Resource
    private CustomerService service;

    @GetMapping
    public Flux<Customer> findAll() {
        return service.findAllCustomers();
    }

    @GetMapping("/{id}")
    public Mono<Customer> findById(@PathVariable Integer id) {
        return service.findCustomerById(id);
    }

    @GetMapping("/name/{lastName}")
    public Flux<Customer> findByLastName(@PathVariable String lastName) {
        return service.findCustomerByLastName(lastName);
    }

    @PostMapping
    public Mono<Customer> create(@RequestBody Customer customer) {
        return service.saveCustomer(customer);
    }

    @PutMapping("/{id}")
    public Mono<Void> update(@PathVariable Integer id, @RequestBody Customer customer) {
        return service.updateCustomer(id, customer);
    }

    @DeleteMapping("/{id}")
    public Mono<Void> delete(@PathVariable Integer id) {
        return service.deleteCustomerById(id);
    }

}
